﻿using Iworld.Author.Model;
using Iworld.basis.Service;
using Iworld.Basis.Help;
using Iworld.Basis.Manager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Iworld.Author.Service.Client.Import
{
    /// <summary>
    /// 编辑二级密码
    /// </summary>
    [DataContract]
    public class EditTwoLevelPasswordImport : CheckAuthorImportBase, IPackageForUpdateModel<IModelToDbContextOfAuthor,Iworld.Author.Model.Author>
    {
        /// <summary>
        /// 存储指针
        /// </summary>
        public int Id
        {
            get
            {
                if (this.Self == null) { return 0; }
                return this.Self.Id;
            }
        }

        /// <summary>
        /// 原二级密码
        /// </summary>
        [DataMember]
        public string OldTwoLevelPassword { get; set; }

        /// <summary>
        /// 新二级密码
        /// </summary>
        [DataMember]
        public string NewTwoLevelPassword { get; set; }


        public void CheckData(IModelToDbContextOfAuthor db)
        {
            this.OldTwoLevelPassword = EncryptHelper.EncryptByMd5(this.OldTwoLevelPassword);
            if (this.Self.TwoLevelPassword != this.OldTwoLevelPassword)
            {
                throw new Exception("原二级密码不正确");
            }
            this.NewTwoLevelPassword = EncryptHelper.EncryptByMd5(this.NewTwoLevelPassword);
        }

        public void Update(Iworld.Author.Model.Author model)
        {
            model.TwoLevelPassword = NewTwoLevelPassword;
        }
    }
}
